﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UMLSynthesizer.CSharpAnalyzer;
using UMLSynthesizer.LangAnalyzer;

namespace UMLSynthesizer.Tasks
{
    class Language
    {
        #region Constructor

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="name">The name of the language</param>
        /// <param name="fileExtensions">File extensions of source</param>
        /// <param name="analyzer">The language analyzer</param>
        public Language(string name, IEnumerable<string> fileExtensions, LanguageAnalyzer analyzer = null)
        {
            this.Name = name;
            this.FileExtensions = fileExtensions;
            this.Analyzer = analyzer;
        }

        #endregion

        #region Public Interface

        public override string ToString()
        {
            return Name;
        }

        #endregion

        #region Properties

        /// <summary>
        /// The name of the language
        /// </summary>
        public string Name { get; private set; }
        /// <summary>
        /// File extensions of source
        /// </summary>
        public IEnumerable<string> FileExtensions { get; private set; }
        /// <summary>
        /// True if there is an analyzer for this language, false otherwise
        /// </summary>
        public bool HasAnalyzer { get { return Analyzer != null; } }
        /// <summary>
        /// The analyzer for this language
        /// </summary>
        public LanguageAnalyzer Analyzer { get; private set; }

        #endregion

        #region Static Languages

        static Language _c;
        static Language _cpp;
        static Language _cSharp;
        static Language _java;
        public static Language C
        {
            get
            {
                if (_c == null)
                    _c = new Language("C", new string[] { ".h", ".c" });
                return _c;
            }
        }
        public static Language Cpp
        {
            get 
            {
                if(_cpp == null)
                    _cpp = new Language("C++", new string[] { ".h", ".hh", ".cpp", ".cc" });
                return _cpp;
            }
        }
        public static Language CSharp
        {
            get 
            {
                if(_cSharp == null)
                    _cSharp = new Language("C#", new string[] { ".cs" },
                        new CSharpLanguageAnalyzer());
                return _cSharp;
            }
        }
        public static Language Java
        {
            get
            {
                if(_java == null)
                    _java = new Language("Java", new string[] { ".java" });
                return _java;
            }
        }

        #endregion
    }
}
